<template>
  <el-select v-model="currentValue"
             :name="name"
             :placeholder="placeholder"
             :clearable="clearable"
             :disabled="disabled"
             @change="select($event)">
    <el-option v-for="item in dictList" :key="item.code" :label="item.value" :value="item.code">
    </el-option>
  </el-select>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'DictSelect',
  props: {
    value: {
      type: [String, Number]
    },
    typeCode: String,
    name: String,
    placeholder: String,
    clearable: Boolean,
    disabled: Boolean
  },
  computed: {
    ...mapGetters(['getDictCacheListByType'])
  },
  data() {
    return {
      currentValue: this.value,
      dictList: []
    }
  },
  methods: {
    select(val) {
      this.$emit('input', val)
      this.$emit('on-select', val)
    }
  },
  mounted() {
    this.dictList = this.getDictCacheListByType(this.typeCode)
  },
  watch: {
    value(val) {
      this.currentValue = val
    }
  }
}
</script>

<style scoped>

</style>
